<?php
/**
 * This is only a simple demo.
 * It is a free software; you can redistribute it 
 * and/or modify it. 
 */
require_once("../comm/config.php");
require_once("get_request_token.php");
	$_SESSION['qq_code'] = $_REQUEST['code'];
	if($_SESSION['qq_code']){
		$qq_access_token = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=".$_SESSION["appid"]."&client_secret=".$_SESSION["appkey"]."&code=".$_SESSION['qq_code']."&state=text&redirect_uri=http://local.iknowy.com/lib/apilogin/qqlogin/oauth/get_access_token.php";
		$ress = file_get_contents($qq_access_token);
		if($ress){
			$access_token=substr($ress,13,32);//去除前面
			$_SESSION['access_token'] = $access_token;
		}
	}
	
	$graph_url = "https://graph.qq.com/oauth2.0/me?access_token=".$_SESSION['access_token']; 
	$strs  = file_get_contents($graph_url);
	if (strpos($strs, "callback") !== false)
     {
        $lpos = strpos($strs, "(");
        $rpos = strrpos($strs, ")");
        $strss  = substr($strs, $lpos + 1, $rpos - $lpos -1);
     }
     $user = json_decode($strss);
     $_SESSION['openid'] = $user->openid;
     $callback = $_SESSION['callback']."?&openid=".$user->openid;
   	 header("Location:".$callback);
?>
